#include <regx52.h>
#include "oled.h"
#include "DHT11.h"

int warning_temperature = 30,warning_Humidity = 60;


void main(){
    struct DHT11_Data *Data;
    int I_t,D_t,I_h,D_h;
    //struct DHT11_Origin_Data *origin_data;
    DHT11_Init();
    OLED_Init();
    OLED_ShowString(1,1,"Temperature:");
    OLED_ShowString(3,1,"Humidity:");
    
    while(1){
        Data = DHT11_readData();
        I_t = (int)Data->Temperature;
        D_t = (int) ((Data->Temperature - I_t)*1000);
        if(I_t > 100) continue;
        else if (I_t >= warning_temperature)
        {
            OLED_ShowString(2,1,"T over ");
        }
        else
        {
            OLED_ShowChar(2,4,'.');
            OLED_ShowNum(2,1,I_t,3);
            OLED_ShowNum(2,5,D_t,3);
        }

        I_h = (int)Data->Humidity;
        D_h = (int) ((Data->Humidity - I_h)*1000);
        if(I_h > 100) continue;
        else if (I_h >= warning_Humidity)
        {
            OLED_ShowString(4,1,"H over ");
        }
        else
        {
            OLED_ShowChar(4,4,'.');
            OLED_ShowNum(4,1,I_h,3);
            OLED_ShowNum(4,5,D_h,3);
        }
    }
  
}


    // origin_data = DHT11_ReceiveData();
    // OLED_ShowNum(1,1,origin_data->Temperature_H,3);
    // OLED_ShowNum(1,5,origin_data->Temperature_L,3);
    // OLED_ShowNum(2,1,origin_data->Humidity_H,3);
    // OLED_ShowNum(2,5,origin_data->Humidity_L,3);
    //OLED_ShowNum(3,1,origin_data->Check,3);